package com.sicong.admin.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sicong.admin.entity.User;
import com.sicong.admin.dto.UserInfo;
import com.sicong.admin.mapper.UserMapper;
import com.sicong.admin.service.PermissionService;
import com.sicong.admin.service.RoleService;
import com.sicong.admin.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author chenww
 * @since 2020-11-25
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Resource
    private RoleService roleService;

    @Resource
    private PermissionService permissionService;

    @Override
    public UserInfo findUserInfo(User user) {
        UserInfo userInfo = new UserInfo();
        List<Long> roles = roleService.findRolesByUserId(user.getId());
        List<String> permissions = permissionService.findPermissionsByRoleId(roles);
        userInfo.setUser(user);
        userInfo.setRoles(roles);
        userInfo.setPermissions(permissions);
        return userInfo;
    }

}
